package com.geostar.constructionland.analyse.controller;

import com.geostar.constructionland.analyse.entity.model.AnalyseQueryModel;
import com.geostar.constructionland.analyse.service.dataquery.AnalyseDataService;
import com.geostar.constructionland.common.entity.response.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 数据查询
 */

@Slf4j
@Api(value = "数据查询接口")
@RestController
public class DataQueryController {

    @Autowired
    AnalyseDataService analyseDataService;
    @ApiModelProperty(value = "分析数据查询")
    @PostMapping(value = "/data/query")
    @ResponseBody
    public ServerResponse dataQuery(@RequestBody @Valid AnalyseQueryModel analyseQueryModel) {
        try {
            List results = analyseDataService.getAnalyseData(analyseQueryModel);
            return ServerResponse.createBySuccess(results);
        }catch (Exception e){
            return ServerResponse.createByErrorMessage(e.getMessage());
        }
    }
}
